<?php
/*
 * @author Carlos Roberto Alvarez Muñoz <ingcram@gmail.com>
 */
Load::models('categorias');
class Subcategorias extends ActiveRecord
{
    public $debug = FALSE; 
    
    public function initialize(){ 	
        $this->belongs_to('categorias');	
    }
    
    public function getSubcategoria($subcategoria_id)
    {
        return $this->find_first($subcategoria_id);
    }
    
    public function getActivo($subcategoria_id)
    {
        return $this->find($subcategoria_id);
    }
	
    public function getActivos($page=1)
    {
        return $this->paginate("page: $page", 'order: id desc');
    }
    
    public function getCategorias($categoria_id)
    {
        return $this->find("categorias_id = $categoria_id");
    }
	
    public function guardar()
    {
        return $this->save();
    }
	
    public function buscar($subcategoria_id)
    {
        return $this->find($subcategoria_id);
    }
    
    public function eliminar($subcategoria_id)
    {
        return $this->delete($subcategoria_id);
    }
    
    public function getByName($subcategoria_name)
    {
        return $this->find_first("nombre = '$subcategoria_name'");                      
    }
    
    public function getIdByName($subcategoria_name)
    {
        $this->find_first("nombre = '$subcategoria_name'");
        
        return $this->id;        
    }
    
}